<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="cake.dao.*"%>
<%@page import="cake.bean.*"%>
<%@page import="cake.db.MySqlDb"%>
<%@page import="java.sql.ResultSet"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>Administrator Cake Management page</title>
		<link rel="stylesheet" href="styles/style.css" type="text/css" />
		<script src="scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
		<script src="scripts/jquery.select.js" type="text/javascript"></script>
		<script src="scripts/tools.js" type="text/javascript"></script>
		<script src="scripts/script.js" type="text/javascript"></script>
	</head>
	<body>
		<div id="container">
			<div id="header">
				<div style="padding-top: 50px;">
					<div class=" btn" style="margin-left: 50px;"> <%
 	String manager = null;
 	long managerId = 0;
 	manager = (String) session.getAttribute("managername");
 	managerId = (Long) session.getAttribute("managerid");
 	if (manager == null || manager.equals("")) {
 		response.sendRedirect("admin.jsp");
 	} else {
 %> Welcome: <%=manager%> 
						 <%
 	}
 %> </div>
 	<div style="margin-left:500px;">
 		<span style="margin-left:10px;cursor:pointer" onclick="toURL('orders.jsp');">Orders</span>
 		<span style="margin-left:10px;cursor:pointer" onclick="toURL('adminComments.jsp');">Comments</span>
 		<span style="margin-left:10px;cursor:pointer" onclick="toURL('adminCakes.jsp');">Cakes</span>
 	</div>
 	<div class="pointer" style="margin-left:900px;" onclick="adminQuit();">Quit</div>
				</div>
				
			</div>
			<div id="content">
				<div style="margin-left: 1px;">
					<div style="padding: 40px 5px 40px 5px;">
						<div  style="min-height:500px;margin-left:300px;">
							<div id="orderList">
							<form name="upload_form" id="upload_form" action="UserServlet?action=diy" method="POST" enctype="multipart/form-data"  target="hidden_frame">
							<table border="1" cellpadding="0" cellspacing="0" style="margin-top:5px;border-collapse: collapse;" bordercolor="#CCCCCC">
								<%
									String id = request.getParameter("id");
									Cake cake=null;
									List<Category> list=new CategoryDao().getCategorys(0,0,"");
									
									if(id!=null)
									{
										CakeDao cDao=new CakeDao();
										cake=cDao.getCake(Long.parseLong(id));
									}
									
									if(cake!=null)
									{
									%>
										<tr>
											<td>Name:</td><td><input type="text" value="<%=cake.getName() %>" id="name" /></td>
											<td>Price:</td><td><input type="text" value="<%=cake.getPrice() %>" id="price" /></td>
										</tr>
										<tr>
											<td>Category:</td><td>
												<select id="category">
													<%
														for(int i=0;i<list.size();i++)
														{
														if(list.get(i).getId()==cake.getCategoryId())
														{
														%>
														<option value="<%=list.get(i).getId() %>"><%=list.get(i).getName() %></option>
														<%
														}
														}
													 %>
												</select>
											</td>
											<td>Valid:</td><td>
												<select id="valid">
													<option value="1">yes</option>
													<option value="0">no</option>
												</select>
											</td>
											<%
												String temp="";
												temp+="<script>";
												temp+="$('#category').setSelectedValue('"+cake.getCategoryId()+"');";
												temp+="$('#valid').setSelectedValue('"+cake.getValid()+"');";
												temp+="</script>";
											 %>
											 <%=temp %>
										</tr>
										<tr>
											<td>Picture:</td>
											<td colspan="3"><input type="file" name="pic_path2" id="pic_path2" value="<%=cake.getPicture() %>"/> 
										<iframe name='hidden_frame' id="hidden_frame" style="display:none"></iframe></td>
										</tr>
										<tr>
											<td>Remark:</td>
											<td colspan="3"><input type="text" value="<%=cake.getRemark() %>" id="remark" style="width:350px;"/></td>
										</tr>
										<tr style="text-align:center;">
											<td colspan="2"><input type="button" value="submit" onclick="addCake(<%=id %>);" /></td>
											<td colspan="2"><input type="button" value="cancel" onclick="toURL('adminCakes.jsp');" /></td>
										</tr>
									<%
									}
									else
									{
									%>
									<tr>
											<td>Name:</td><td><input type="text" value="" id="name" /></td>
											<td>Price:</td><td><input type="text" value="" id="price" /></td>
										</tr>
										<tr>
											<td>Category:</td><td>
												<select id="category">
													<%
														for(int i=0;i<list.size();i++)
														{
														%>
														<option value="<%=list.get(i).getId() %>"><%=list.get(i).getName() %></option>
														<%
														}
													 %>
												</select>
											</td>
											<td>Valid:</td><td>
												<select id="valid">
													<option value="1">yes</option>
													<option value="0">no</option>
												</select>
											</td>
										</tr>
										<tr>
											<td>Picture:</td>
											<td colspan="3"><input type="file" name="pic_path2" id="pic_path2"/> 
										<iframe name='hidden_frame' id="hidden_frame" style="display:none"></iframe></td>
										</tr>
										<tr>
											<td>Remark:</td>
											<td colspan="3"><input type="text" value="" id="remark"  style="width:350px;"/></td>
										</tr>
										<tr style="text-align:center;">
											<td colspan="2"><input type="button" value="submit" onclick="addCake();" /></td>
											<td colspan="2"><input type="button" value="cancel" onclick="toURL('adminCakes.jsp');" /></td>
										</tr>
									<%
									}
								%>
							</table>
							</form>
							</div>
						</div>
					</div>
				</div>
				<div id="categorys">
					<div style="margin-top:30px;">
						<hr />
						<div style="margin-left:250px;">
							Address：Beijing chaoyang district pingleyuan 100   phone：400-678-5618<br/>  
							Email： <a href=mailto:sample@163.com>a87980011@163.com</a> <br/>
							All Rights Reserved.：Laomo（jingsong branch）<br/>
						</div>
					</div>
				</div>
			</div>
		</div>
	</body>
</html>
